package com.gitee.huxing.course.conc.task;

import java.util.concurrent.FutureTask;

/**
 * @Description:
 * @ProjectName: JavaCourse
 * @Package: com.gitee.huxing.course.conc.task
 * @ClassName: TaskService01Impl
 * @Author: huxing
 * @DateTime: 2021-08-25 下午4:58
 */
public class TaskThreadPool01 extends AbstractTaskThreadPool{

    public static void main(String[] args) throws InterruptedException{
        new TaskThreadPool01().task();
    }

    @Override
    public int threadTask() {
        try {
            FutureTask<Integer> future = new FutureTask<>(() -> CourseTask.sum());
            // 启动线程
            new Thread(future).start();
            // 返回结果
            return future.get().intValue();
        } catch (Exception ex){
           ex.printStackTrace();
           return 0;
        }
    }
}
